package org.jsola.hr.constant.convert;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import org.jsola.common.SafeKit;
import org.jsola.hr.constant.EmployRangeEnum;

/**
 *【适用聘用形式】excel导入导出时字段值转换
 * @author zhuhaoran
 */
public class EmployRangeEnumConverter implements Converter<String> {

    @Override
    public Class supportJavaTypeKey() {
        return String.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        EmployRangeEnum employRangeEnum = EmployRangeEnum.findByDesc(cellData.getStringValue());
        if (employRangeEnum == null) {
            return cellData.getStringValue();
        }
        return employRangeEnum.getValue();
    }

    @Override
    public CellData convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        EmployRangeEnum employRangeEnum = EmployRangeEnum.find(value);
        if (employRangeEnum == null) {
            return new CellData(value);
        }
        return new CellData(employRangeEnum.getDesc());
    }
}
